﻿using System;

namespace AspectCore.DependencyInjection
{
    /// <summary>
    /// 由委托创建服务的服务描述
    /// </summary>
    public class DelegateServiceDefinition : ServiceDefinition
    {
        /// <summary>
        /// 由委托创建服务的服务描述
        /// </summary>
        /// <param name="serviceType">服务类型</param>
        /// <param name="implementationDelegate">用于创建服务的委托</param>
        /// <param name="lifetime">生命周期</param>
        public DelegateServiceDefinition(Type serviceType, Func<IServiceResolver, object> implementationDelegate, Lifetime lifetime) : base(serviceType, lifetime)
        {
            ImplementationDelegate = implementationDelegate ?? throw new ArgumentNullException(nameof(implementationDelegate));
        }

        /// <summary>
        /// 用于创建服务的委托
        /// </summary>
        public Func<IServiceResolver, object> ImplementationDelegate { get; }
    }
}